#!/bin/bash

if [[ $# -ne 1 ]]; then
	echo "Usage:   influx-proxy.sh status|start|stop|restart"
	exit
elif [[ $1 = "restart" ]]; then
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] influx-proxy restarting ..."
	systemctl restart influx-proxy
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(1)'172.24.16.31' restarted."
	ssh root@proxy02 "systemctl restart influx-proxy"
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(2)'172.24.16.30' restarted."
elif [[ $1 = "start" ]]; then
        echo "[`date +"%Y-%m-%d %H:%M:%S"`] influx-proxy starting ..."
        systemctl start influx-proxy
        echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(1)'172.24.16.31' is running."
        ssh root@proxy02 "systemctl start influx-proxy"
        echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(2)'172.24.16.30' is running."
elif [[ $1 = "stop" ]]; then
        echo "[`date +"%Y-%m-%d %H:%M:%S"`] influx-proxy stoping ..."
        systemctl stop influx-proxy
        echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(1)'172.24.16.31' stopped."
        ssh root@proxy02 "systemctl stop influx-proxy"
        echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(2)'172.24.16.30' stopped."
elif [[ $1 = "status" ]]; then
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(1)'172.24.16.31' --------------------------------->"
        systemctl status influx-proxy
	echo "[`date +"%Y-%m-%d %H:%M:%S"`] Proxy Server(2)'172.24.16.30' --------------------------------->"
        ssh root@proxy02 "systemctl status influx-proxy"
else
	echo "command argument wrong!"
	echo "Usage:   influx-proxy.sh status|start|stop|restart"
	exit
fi